import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:getx_scaffold/common/widgets/icon_x.dart';
import 'package:getx_scaffold/getx_scaffold.dart';
import 'package:oramemo/generated/assets.dart';
import 'package:oramemo/pages/facility/facility_home/view/device_widget.dart';
import 'package:oramemo/pages/transcription/files/controllers/transcriptio_files_logic.dart';
import 'package:oramemo/pages/transcription/transcription_router.dart';
import 'package:oramemo/widget/my_refresh.dart';

import 'ai_transcription_item.dart';
import 'ai_transcription_logic.dart';
import 'file_move_sheet.dart';
import 'file_select_sheet.dart';

class AiTranscriptionPage extends StatelessWidget {
  const AiTranscriptionPage({super.key});

  @override
  Widget build(BuildContext context) {
    final fileLogic = Get.put(TranscriptionFilesLogic());
    return GetBuilder<AiTranscriptionLogic>(
        init: AiTranscriptionLogic(),
        builder: (logic) {
          final data = logic.controller.voiceRecords;
          return Column(
            children: [
              // Device Info Card
              DeviceWidget(data: logic.state.data),
              // Title
              Padding(
                padding: const EdgeInsets.only(
                    top: 12, bottom: 12, left: 16, right: 30),
                child: Row(
                  children: [
                    InkWell(
                      onTap: () {
                        Get.bottomSheet(FileSelectSheet());
                      },
                      child: Row(
                        children: [
                          const IconX.image(
                            Assets.homeFile,
                            size: 24,
                          ),
                          const SizedBox(width: 2),
                          Text(
                            '${fileLogic.currentFolder.value.folderName ?? ''}（${data.length}）',
                            style: const TextStyle(
                              fontSize: 18,
                              fontWeight: FontWeight.bold,
                            ),
                          ),
                        ],
                      ),
                    ),
                    const Spacer(),
                    InkWell(
                        onTap: () {
                          Get.toNamed(
                              TranscriptionRouter.transcriptionFileList);
                        },
                        child: const IconX.image(
                          Assets.homeDir,
                          size: 24,
                        ))
                  ],
                ),
              ),

              // Transcription List
              Expanded(
                  child: MyRefresh(
                      onRefresh: () {
                        logic.onLoad();
                        fileLogic.loadFolders();
                      },
                      onLoad: () {logic.requestData(page: logic.state.page + 1);},
                      child: ListView.builder(
                        padding: const EdgeInsets.symmetric(horizontal: 16),
                        itemCount: data.length,
                        itemBuilder: (context, index) {
                          return AiTranscriptionItme(
                            data: data[index],
                            onTap: () {
                              Get.toNamed(
                                  TranscriptionRouter.transcriptionDetails,
                                  arguments: data[index].id);
                              data[index].readStatus = 0;
                            },
                            onLongPress: () {
                              Get.bottomSheet(FileMoveSheet(data: data[index],));
                            },
                          );
                        },
                      ))),
            ],
          );
        });
  }
}
